﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtility;

public partial class Manageweb_Control_LeftNews : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TV_NewsDataBind();
    }


    protected void TV_NewsDataBind()
    {
        string SQLstr = "SELECT * FROM [NewsClass] WHERE [NC_IsLock]=false";

        DataSet DS_NewsClass = AccHelper.GetDataSet(SQLstr, "NewsClass");

        DataTable DT_NewsClass = DS_NewsClass.Tables["NewsClass"];

        InitTree(TV_News.Nodes[0].ChildNodes[1].ChildNodes, "0", DT_NewsClass);

        DS_NewsClass.Clear();

        DS_NewsClass.Dispose();
    }


    private void InitTree(TreeNodeCollection tnParent, string parentId, DataTable dt)
    {
        foreach (DataRow dr in dt.Select("[NC_ParentID]='" + parentId + "'"))
        {
            TreeNode tn = new TreeNode();
            TreeNode tn2 = new TreeNode();

            tn.Value = dr["NC_ID"].ToString();
            tn.Text = dr["NC_Title"].ToString();
            tn.Target = "mainFrame";
            tn.NavigateUrl = "~/Manageweb/ManageNews/ManageNews.aspx?ClassID=" + dr["NC_ID"].ToString();

            tnParent.Add(tn);

            //tn2.Value = "添加";
            //tn2.Text = "添加" + dr["NC_Title"].ToString();
            //tn2.Target = "mainFrame";
            //tn2.NavigateUrl = "~/Manageweb/ManageNews/AddNews.aspx?ClassID=" + dr["NC_ID"].ToString();

            //tnParent.Add(tn2);

            InitTree(tnParent[tnParent.Count - 1].ChildNodes, tn.Value, dt);
        }
    }
}
